# 定义类
class Person(object):
    n = 10  # 类变量,所有实例共享
    # 构造方法,self为创建的实例本身,即hou,yao等
    def __init__(self, name, sex, age = 25): # 指定默认属性,可不传
        self.name = name   # 实例变量,属于实例
        self.sex = sex
        self.age = age
    # self为调用实例本身
    def work(self):
        print("%s 的年龄是 %s,性别%s,正在工作" % (self.name, self.age, self.sex))
    def eat(self, food):
        print("{NAME} 吃了 {FOOD}".format(NAME=self.name, FOOD=food))
# 实例类的对象
hou = Person("侯征", "男", 30)
print(Person.n)  # 10
print(hou.n)  # 10,会先从实例变量中找,找不到再去类变量找
hou.n = 30
print(hou.n)  # 30
yao = Person("姚振", "女")
he = Person("何毅", 1)
# 调用类的函数时,python会自动把调用者传递到参数中,即 Person.work(hou)
hou.work()
yao.work()
he.eat("肉夹馍")